/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BeansNegocio;

import Servicios.GraficaLocal;
import Servicios.GraficaRemote;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;

/**
 *
 * @author Pablo Manuel Hurtado
 */
@Stateless
public class Grafica implements GraficaRemote, GraficaLocal {


    private final static String RUTA="C:/Users/Pablo Manuel Hurtado/Documents/NetBeansProjects/trunk/Arquitech/Arquitech-ejb/data/data.txt";
    /**
     * representa el titulo de la grafica
     */
    private String tituloGrafica;
    private String tituloEjeX;
    private String tituloEjeY;
    private List data;
    private double[] tiempoTotal;
    private double[] tiempoIndividual;
    private String[] axisLabels;
    private String[] labels;

    /** Creates a new instance of Graphics */
    public Grafica() {

        tituloEjeX = null;
        tituloEjeY = "Tiempo (ms)";
        tituloGrafica = null;

        labels = new String[2];

        data = new ArrayList();

        ArrayList<String> rotulo = new ArrayList<String>();

        try
        {
        File f = new File(RUTA);
        
        FileReader fr = new FileReader(f);
        BufferedReader bf = new BufferedReader(fr);

        String a = bf.readLine();
        while (a != null) {
            if (a.contains("titulo")) {
                tituloGrafica = a.split(":")[1];
            } else if (a.contains("columnas")) {

                tituloEjeX = a.split(":")[1].split(",")[0];

                labels[0] = a.split(":")[1].split(",")[1];
                labels[1] = a.split(":")[1].split(",")[2];

            } else {

                rotulo.add(a.split(",")[0]);
                tiempoTotal = new double[2];

                tiempoTotal[0] = Double.parseDouble(a.split(",")[1]);
                tiempoTotal[1] = Double.parseDouble(a.split(",")[2]);
                data.add(tiempoTotal);
            }


            a = bf.readLine();
        }
        axisLabels= new String[rotulo.size()];
        for(int i =0; i<rotulo.size();i++)
        {
            axisLabels[i]= rotulo.get(i);
        }
        }
        catch(Exception e)
        {
            File f= new File("C:/Users/Pablo Manuel Hurtado/Downloads/data.txt");
            PrintWriter p=null;
            try {
                p = new PrintWriter(f);
                e.printStackTrace(p);
                p.flush();
                p.close();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Grafica.class.getName()).log(Level.SEVERE, null, ex);
            }
          
        }


    }

    @Override
    public List getData() {
        return data;
    }

    @Override
    public void setData(List data) {
        this.data = data;
    }

    @Override
    public String[] getLabels() {

        return labels;
    }

    @Override
    public void setLabels(String[] labels) {
        this.labels = labels;
    }

    @Override
    public String[] getAxisLabels() {

        return axisLabels;

    }

    @Override
    public void setAxisLabels(String[] axisLabels) {
        this.axisLabels = axisLabels;
    }

    @Override
    public double[] getTiempoTotal() {

        return tiempoTotal;
    }

    @Override
    public void setTiempoTotal(double[] tiempoTotal) {
        this.tiempoTotal = tiempoTotal;
    }

    @Override
    public String getTituloEjeX() {
        return tituloEjeX;
    }

    @Override
    public void setTituloEjeX(String tituloEjeX) {
        this.tituloEjeX = tituloEjeX;
    }

    @Override
    public String getTituloEjeY() {
        return tituloEjeY;
    }

    @Override
    public void setTituloEjeY(String tituloEjeY) {
        this.tituloEjeY = tituloEjeY;
    }

    @Override
    public String getTituloGrafica() {
        return tituloGrafica;
    }

    @Override
    public void setTituloGrafica(String tituloGrafica) {
        this.tituloGrafica = tituloGrafica;
    }
}
